package com.tedu.account.controller;

import com.tedu.account.pojo.dto.AccountQuery;
import com.tedu.account.pojo.dto.AccountSaveParam;
import com.tedu.account.pojo.vo.AccountVO;
import com.tedu.account.service.AccountService;
import com.tedu.common.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/account")
public class AccountController {
    @Autowired
    AccountService accountService;
    @PostMapping("/save")
    public JsonResult save(AccountSaveParam accountSaveParam){
        log.debug("账户保存:{}", accountSaveParam);
        accountService.saveAccount(accountSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("/select")
    public JsonResult select(AccountQuery accountQuery){
        log.debug("账户查询:{}", accountQuery);
        List<AccountVO> list = accountService.selectAccount(accountQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Integer id){
        log.debug("账户删除:{}", id);
        accountService.deleteAccount(id);
        return JsonResult.ok();
    }
}
